package com.ruoyi.project.system.jilu.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.jilu.domain.KamiJilu;
import com.ruoyi.project.system.jilu.service.IKamiJiluService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 卡密使用记录Controller
 * 
 * @author ruoyi
 * @date 2023-02-28
 */
@Controller
@RequestMapping("/system/jilu")
public class KamiJiluController extends BaseController
{
    private String prefix = "system/jilu";

    @Autowired
    private IKamiJiluService kamiJiluService;

    @RequiresPermissions("system:jilu:view")
    @GetMapping()
    public String jilu()
    {
        return prefix + "/jilu";
    }

    /**
     * 查询卡密使用记录列表
     */
    @RequiresPermissions("system:jilu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KamiJilu kamiJilu)
    {
        startPage();
        List<KamiJilu> list = kamiJiluService.selectKamiJiluList(kamiJilu);
        return getDataTable(list);
    }

    /**
     * 导出卡密使用记录列表
     */
    @RequiresPermissions("system:jilu:export")
    @Log(title = "卡密使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KamiJilu kamiJilu)
    {
        List<KamiJilu> list = kamiJiluService.selectKamiJiluList(kamiJilu);
        ExcelUtil<KamiJilu> util = new ExcelUtil<KamiJilu>(KamiJilu.class);
        return util.exportExcel(list, "卡密使用记录数据");
    }

    /**
     * 新增卡密使用记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存卡密使用记录
     */
    @RequiresPermissions("system:jilu:add")
    @Log(title = "卡密使用记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KamiJilu kamiJilu)
    {
        return toAjax(kamiJiluService.insertKamiJilu(kamiJilu));
    }

    /**
     * 修改卡密使用记录
     */
    @RequiresPermissions("system:jilu:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        KamiJilu kamiJilu = kamiJiluService.selectKamiJiluById(id);
        mmap.put("kamiJilu", kamiJilu);
        return prefix + "/edit";
    }

    /**
     * 修改保存卡密使用记录
     */
    @RequiresPermissions("system:jilu:edit")
    @Log(title = "卡密使用记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KamiJilu kamiJilu)
    {
        return toAjax(kamiJiluService.updateKamiJilu(kamiJilu));
    }

    /**
     * 删除卡密使用记录
     */
    @RequiresPermissions("system:jilu:remove")
    @Log(title = "卡密使用记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kamiJiluService.deleteKamiJiluByIds(ids));
    }
}
